package com.fjut.pms.action;

import java.awt.geom.Area;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.fjut.pms.pojo.Employee;
import com.fjut.pms.pojo.TransferLog;
import com.fjut.pms.service.ITransferService;
import com.fjut.pms.utils.PageBean;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class TransferAction extends ActionSupport implements
		ModelDriven<PageBean> {

	private static final long serialVersionUID = 1693341513665556906L;
	private ITransferService tranService;
	private PageBean page = new PageBean();
	private TransferLog tran = new TransferLog();
	private List departs=new ArrayList();
	private List<Employee> emps=new ArrayList();
	private String depart;
	private int id;

	public String show() {
		page = tranService.findTransefer(page, id);
		return "show";
	}

	public String getemp(){
		HttpServletResponse response=ServletActionContext.getResponse();
		if(depart==null||depart.length()<=0)return null;
		emps=tranService.findEmpsByD(depart);
		response.setContentType("text/xml;charset=UTF-8");
		try {
			StringBuffer xml=new StringBuffer();
			xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			xml.append("<emps>");
			for(Employee i:emps){
				xml.append("<name>");
				xml.append(i.getName());
				xml.append("</name>");
			}
			xml.append("</emps>");
			PrintWriter pw=response.getWriter();
			pw.println(xml.toString());
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}		
		return null;
	}
	
	public String add() {
		tranService.save(tran);
		return "add";
	}
	public String toadd(){
		departs=tranService.findDeparts();
		return "toadd";
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public ITransferService getTranService() {
		return tranService;
	}

	public void setTranService(ITransferService tranService) {
		this.tranService = tranService;
	}

	public PageBean getPage() {
		return page;
	}

	public void setPage(PageBean page) {
		this.page = page;
	}

	public TransferLog getTran() {
		return tran;
	}

	public void setTran(TransferLog tran) {
		this.tran = tran;
	}

	public PageBean getModel() {
		return this.getPage();
	}

	public List getDeparts() {
		return departs;
	}

	public void setDeparts(List departs) {
		this.departs = departs;
	}

	public String getDepart() {
		return depart;
	}

	public void setDepart(String depart) {
		this.depart = depart;
	}

	public List getEmps() {
		return emps;
	}

	public void setEmps(List emps) {
		this.emps = emps;
	}

}
